<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/8/2
 * Time: 10:07
 */
function changeType($goodstype){
    $type=D('type');
    $ret=$type->where(array('typeid'=>$goodstype))->find();
    return $ret['typename'];
}
function changeUnit($goodsunit){
    $unit=D('unit');
    $ret=$unit->where(array('unitid'=>$goodsunit))->find();
    return $ret['unitname'];
}
function uploadImg($name,$defualt){
    if ($_FILES[$name]['error'] < 4) {
        $cfg = array(
            'exts' => array('BMP','PNG','JPEG','GIF','JPG','bmp','png','jpeg','gif','jpg'), //允许上传的文件后缀
            'autoSub' => true, //自动子目录保存文件
            'subName' => array('date', 'Y-m-d'), //子目录创建方式，[0]-函数名，[1]-参数，多个参数使用数组
            'rootPath' => './Public/Uploads/', //保存根路径
            'savePath' => '', //保存路径
            'saveName' => array('uniqid', ''), //上传文件命名规则，[0]-函数名，[1]-参数，多个参数使用数组
        );
        $upload = new \Think\Upload($cfg);
        $ret = $upload->uploadOne($_FILES[$name]);
        $img = $upload->rootPath . $ret['savepath'] . $ret['savename'];
    } else {
        $img =$defualt;
    }
    return $img;
}